package services

import (
    "context"
    "gitee.com/go-libs/db-xorm/db"
    "integration/app/models"
    "integration/app/requests/shop/order"
)

func (o *OrderStatusService) GetByStatusRequest(ctx context.Context, req *order.StatusRequest) (model *models.OrderStatus, err error) {
    var (
        has  bool
        sess *db.Session
    )

    // Open a session from slave server.
    if sess, err = o.Slave(ctx); err != nil {
        return
    }

    // Prepare result.
    model = &models.OrderStatus{}

    // Send search request.
    if has, err = sess.Where("oid = ? AND change_type = ? AND change_time = ?", req.Oid, req.ChangeType, req.ChangeTime).Get(model); err != nil || !has {
        model = nil
    }
    return
}
